package com.kczd.jinlan.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kczd.jinlan.R;
import com.kczd.jinlan.adapter.TabLayoutAdapter;
import com.kczd.jinlan.fragment.orderfragment.DaipeihuoFragment;
import com.kczd.jinlan.fragment.orderfragment.DaishouhuoFragment;
import com.kczd.jinlan.fragment.orderfragment.DaizhifuFragment;
import com.kczd.jinlan.fragment.orderfragment.QuanbuFragment;
import com.kczd.jinlan.fragment.orderfragment.YiwanchengFragment;
import com.kczd.jinlan.utils.OrderUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * yang_g
 * 订单模块
 * Created by Administrator on 2017/5/15.
 */

public class OrderFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private View view;

    private List<Fragment> list;
    private String[] titles = {"全部", "待支付", "待配货", "待收货","已完成"};
    private TabLayoutAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.order_fragment,null);
        initView();
        return view;
    }

    private void initView() {
        //实例化
        viewPager = (ViewPager)view.findViewById(R.id.viewpagers);
        tabLayout = (TabLayout)view.findViewById(R.id.tablayouts);

        /**
         * 设置tablayout的长度
         */
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
               OrderUtils.setIndicator(tabLayout, 15, 15);
            }
        });

        //页面，数据源
        list = new ArrayList<>();
        list.add(new QuanbuFragment());
        list.add(new DaizhifuFragment());
        list.add(new DaipeihuoFragment());
        list.add(new DaishouhuoFragment());
        list.add(new YiwanchengFragment());
        //ViewPager的适配器
        adapter = new TabLayoutAdapter(getActivity().getSupportFragmentManager(), list, titles);
        viewPager.setAdapter(adapter);
        //绑定
        tabLayout.setupWithViewPager(viewPager);

    }
}
